package com.syni.mdd.yhd.common.all.dao.jpa.activity;

import com.syni.mdd.yhd.common.all.dao.BaseJPADao;
import com.syni.mdd.yhd.common.all.entity.activity.BmsMealPrize;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface BmsMealPrizeDao extends BaseJPADao<BmsMealPrize,Integer> {
    List<BmsMealPrize> findByIsUse(Integer isUse);

    BmsMealPrize findByIdAndIsUse(Integer id,Integer isUse);

    @Transactional//事务的注解
    @Modifying //增删改必须有这个注解
    @Query(value = "update bms_meal_prize set remain_num = remain_num - 1,total_num = total_num - 1,update_num_version = update_num_version + 1 " +
            "where id = ?1 and update_num_version = ?2",nativeQuery = true)
    Integer updateRemainNum(Integer id, Integer updateNumVersion);

    @Query(value = "SELECT * FROM bms_meal_prize WHERE id = ?1",nativeQuery = true)
    BmsMealPrize findRemainAndVersion(Integer id);

    BmsMealPrize findByBusinessCouponId(Integer couponId);
}
